{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "74838f36-8243-4124-a0cc-c6ccf386f589",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "System.out.println(\"Hello World\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "596d70a5-fefe-4df5-8fd1-6d4d329ae420",
   "metadata": {},
   "source": [
    "\n",
    "## Create `HelloWorld` class and call the `main` method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "107a947b-4f06-4bb8-9890-ec46220b7e6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "public class HelloWorld {\n",
    "    public static void main(String... args) {\n",
    "        System.out.println(\"Hello World\");\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4ec66c4e-89af-4091-8eff-9d9787a6b817",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World\n"
     ]
    }
   ],
   "source": [
    "HelloWorld.main()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3832de6-287b-44b7-b397-4185a5023000",
   "metadata": {},
   "source": [
    "## Promt javascript alert"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5ff4da03-9bdd-401c-a9eb-5635e325c43e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "alert('Hello from IJava!');"
      ],
      "text/plain": [
       "alert('Hello from IJava!');"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "183e908a-a183-443b-9181-8553aa35b05c"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "display(\"alert('Hello from IJava!');\", \"application/javascript\");"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db5cb1a6-bf1d-41e9-beb8-78b6adbc79f1",
   "metadata": {},
   "source": [
    "## Display markdown "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bbf80d97-2511-409c-a0d3-d9566acef393",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<b>Bold</b>"
      ],
      "text/markdown": [
       "<b>Bold</b>"
      ],
      "text/plain": [
       "<b>Bold</b>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "344269c0-ac30-4561-92e6-9f619b98a5f7"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "display(\"<b>Bold</b>\", \"text/html\", \"text/markdown\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8bbf1f50-f911-49e7-8fff-13090c2397fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "Hello from **IJava**"
      ],
      "text/plain": [
       "Hello from **IJava**"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "String md = \"Hello from **IJava**\";\n",
    "\n",
    "render(md, \"text/markdown\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ab6d994-85cd-4622-903e-212deab47417",
   "metadata": {},
   "source": [
    "## Display countdown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c9b72743-fb65-4fbf-ba22-e9b1980110ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<b>Countdown:</b> 0"
      ],
      "text/plain": [
       "<b>Countdown:</b> 0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<b>Liftoff!</b>"
      ],
      "text/plain": [
       "<b>Liftoff!</b>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "String id = display(\"<b>Countdown:</b> 3\", \"text/html\");\n",
    "for (int i = 3; i >= 0; i--) {\n",
    "    updateDisplay(id, \"<b>Countdown:</b> \" + i, \"text/html\");\n",
    "    Thread.sleep(1000L);\n",
    "}\n",
    "render(\"<b>Liftoff!</b>\", \"text/html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f6dd2b4f-15a1-4715-abc2-20c29178d72d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(int) eval(\"1 + 2\") + 3\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "885e6cfc-f025-42ac-88d0-76d8a8cb7b2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "Object s = eval(\"4 + 2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b8d8d1e6-f133-4de0-b5a8-ab2aa2d1b160",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "617af9c6-8188-4e11-bddd-71ba9ee93902",
   "metadata": {},
   "source": [
    "## Load Maven Dependency"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8e350c3e-03dc-402a-a92d-2e7785399270",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%loadFromPOM\n",
    "<repository>\n",
    "    <id>aliyun-central</id>\n",
    "    <url>https://maven.aliyun.com/repository/central</url>\n",
    "    <releases>\n",
    "        <enabled>true</enabled>\n",
    "    </releases>\n",
    "    <snapshots>\n",
    "        <enabled>true</enabled>\n",
    "    </snapshots>\n",
    "</repository>\n",
    "\n",
    "<dependency>\n",
    "    <groupId>io.github.cdimascio</groupId>\n",
    "    <artifactId>dotenv-java</artifactId>\n",
    "    <version>3.0.0</version>\n",
    "</dependency>\n",
    "\n",
    "<dependency>\n",
    "    <groupId>org.neo4j.driver</groupId>\n",
    "    <artifactId>neo4j-java-driver</artifactId>\n",
    "    <version>5.19.0</version>\n",
    "</dependency>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "16124c92-6ef0-4bc7-93b6-c239fd3bc0fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "import io.github.cdimascio.dotenv.Dotenv;\n",
    "\n",
    "Dotenv dotenv = Dotenv.configure()\n",
    "    .directory(\"/home/jovyan/work\")\n",
    "    .filename(\".env\")\n",
    "    .load();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a1f84d8a-1b24-43ae-aafd-b2d1172e644b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "nomic-embed-text"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dotenv.get(\"embedding_model\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dee9226b-b49e-4a00-8698-1e6ff2d64bf4",
   "metadata": {},
   "outputs": [
    {
     "ename": "EvalException",
     "evalue": "io/netty/channel/EventLoopGroup",
     "output_type": "error",
     "traceback": [
      "\u001b[1m\u001b[31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1m\u001b[31mjava.lang.NoClassDefFoundError: io/netty/channel/EventLoopGroup\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.internal.async.connection.BootstrapFactory.newBootstrap(BootstrapFactory.java:27)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.internal.DriverFactory.createBootstrap(DriverFactory.java:373)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:89)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.internal.DriverFactory.newInstance(DriverFactory.java:73)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:373)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:125)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:110)\u001b[0m",
      "\u001b[1m\u001b[31m\tat org.neo4j.driver.GraphDatabase.driver(GraphDatabase.java:87)\u001b[0m",
      "\u001b[1m\u001b[31m\tat .(#37:1)\u001b[0m"
     ]
    }
   ],
   "source": [
    "import org.neo4j.driver.*;\n",
    "\n",
    "String neo4jUri = dotenv.get(\"neo4j.uri\");\n",
    "String username = dotenv.get(\"neo4j.authentication.username\");\n",
    "String password = dotenv.get(\"neo4j.authentication.password\");\n",
    "\n",
    "Driver driver = GraphDatabase.driver(neo4jUri, AuthTokens.basic(username, password));\n",
    "driver.verifyConnectivity();\n",
    "\n",
    "Session session = driver.session(SessionConfig.builder().withDatabase(database == null?\"neo4j\":database).build());\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcf59510-7f56-4d63-b717-33ce3ead6e19",
   "metadata": {},
   "outputs": [],
   "source": [
    "session.run(\"MATCH (n:SoftwareSystem) RETURN n LIMIT 25\");"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Java",
   "language": "java",
   "name": "java"
  },
  "language_info": {
   "codemirror_mode": "java",
   "file_extension": ".jshell",
   "mimetype": "text/x-java-source",
   "name": "Java",
   "pygments_lexer": "java",
   "version": "23+37-2369"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
